<?php
$state = $_GET['state'];
$code = $_GET['code'];
$url = urldecode($state);
//根据url中有没有“？”来决定使用什么连接符
$connector = FALSE === strpos($url,"?") ? "?" : "&";
header("Location: ".$url.$connector."code=".$code);